package com.bs.common.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author bingshao
 * @date 2022/9/13
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements Serializable {
    private static final long serialVersionUID = -2213014767276639321L;

    private Integer code;

    private String message;

    private T data;

    public static <T> Result<T> success() {
        return new Result<>(200, "成功", null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data);
    }

    public static <T> Result<T> fail() {
        return new Result<>(500, "失败", null);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<>(500, "失败", data);
    }

    public static <T> Result<T> fail(int code, String msg) {
        return new Result(code, msg, null);
    }

    public static <T> Result<T> forbidden(T data) {
        return new Result(403, "无权限", data);
    }

    public static <T> Result<T> unauthorized(T data) {
        return new Result(401, "暂未登录或者token过期", data);
    }

}
